/* 设置一些全局变量 */
const hostname = window.location.hostname;
const port = window.location.port;
window.globalVar = require("../JsonFile/globalVar.json");
if (process.env.NODE_ENV === "development") {
    //开发全局变量配置
    globalVar = globalVar.isDev;
    globalVar.onlyOffice = "http://192.168.107.77/OnlineEditor";
} else {
    if (hostname == "192.168.107.77") {
        //生产环境192.168.107.77全局变量配置
        globalVar = globalVar.is77;
    } else if (hostname == "192.168.107.117") {
        //生产环境192.168.107.117全局变量配置
        globalVar = globalVar.is117;
    } else if (hostname == "kjbk.bjcjl.net") {
        // 陈经纶的配置
        globalVar = globalVar.isCJL;
        globalVar.onlyOffice = "https://kjbk.bjcjl.net/OnlineEditor";
    } else if (hostname == "kt.cnki.net") {
        // 课题的配置
        globalVar = globalVar.isKT;
    } else if (hostname == "edu.cnki.net") {
        // EDU的配置
        globalVar = globalVar.isEDU;
    } else {
        alert("配置文件出错！");
    }
    globalVar.baseURL += window.apiurl;
    if(!globalVar.onlyOffice){
        globalVar.onlyOffice = globalVar.SITEORIGIN + "OnlineEditor";
    }
}
window.isOpenTencentVideo = true;
if(process.env.NODE_ENV === "development"){
    // 测试环境默认父页面传值
    window.dataFromFather = {
        catalogCode: "0e2c73fd-50c2-4b12-bdad-5ebbc95ceca2",
        courseCode: "b1e8d2b2-0fb2-463a-9f6f-3ee68c87f3c8",
        token: "e5e7dbe2abbb4def972e5ae4c6565b20",
        userID: "62f40f1a-2a4f-4e4a-9fe7-87ee597bf632",
        isAdmin: true, // 当前登录人是否是课程负责人
    }
}


/* i18n */
import '../i18n/'
/* Vue */
import Vue from 'vue'
/* 饿了么UI组件 */
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI);
// axios
import axios from 'axios'
window.axios = axios;
import qs from 'qs';
window.qs = qs;
import '../weditor';
import "../cnkiSearch"

// 请求拦截器
axios.interceptors.request.use(function(config) {
    if(process.env.NODE_ENV === "production"){
        config.baseURL = "/" + window.apiurl;
    }
    return config;
}, function(error) {
    //对请求错误做些什么
    return Promise.reject(error);
});

/* 组件 */
import App from './App'
/* vuex数据 */
import store from './store/'

import './core/global.js'
import '../assets/css/iconfont.css'
import '../assets/css/style.css'
import '../assets/css/personal/main.css'
import '../assets/css/personal/toolbar.css'

import htmlToPdf from '../core/util';
Vue.use(htmlToPdf);
/**
 * 页面消息提示
 * @param type 类型
 * @param msg 消息主体
 * @param closeFlag 是否显示关闭按钮，默认显示
 * @param dura 持续时间 0为不关闭
 */
Vue.prototype.globalShowMsg = ({msg, type, closeFlag, dura}) => {
    ElementUI.Message({
        showClose: closeFlag || true,
        message: msg,
        type: type || "error",
        duration: typeof dura === "undefined" ? 2000 : dura
    });
};
/**
 * 检查特殊字符
 */
Vue.prototype.specialCharCheck = (str) => {
    let specialCharRE = /[$*<>`~^|/\\]/g;
    return specialCharRE.test(str);
}
/**
 * 检查腾讯云格式
 */
Vue.prototype.tencentFormatCheck = (str) => {
    let tencentFormatRE = /(WMV|WM|ASF|ASX|RM|RMVB|RA|RAM|MPG|MPEG|MPE|VOB|DAT|MOV|3GP|MP4|MP4V|M4V|MKV|AVI|FLV|F4V)/gi;
    return tencentFormatRE.test(str);
}
/* eslint-disable no-new */
new Vue({
    el: '#app',
    store,
    render: h => h(App)
});
